package reggie.control;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reggie.common.R;
import reggie.dao.OrderDetail;
import reggie.dao.Orders;
import reggie.service.OrdersService;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrdersControl {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("支付成功");
    }

    @GetMapping("/page")
    public R<Page> page(int page, int pageSize, Long number, String beginTime,String endTime){
        Page<Orders> pageInfo = new Page<>(page,pageSize);
        LambdaQueryWrapper<Orders> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(number != null,Orders::getNumber,number);
        lambdaQueryWrapper.le(beginTime !=null,Orders::getCheckoutTime,beginTime)
                .gt(endTime !=null,Orders::getCheckoutTime,endTime);
        ordersService.page(pageInfo, lambdaQueryWrapper);
        return R.success(pageInfo);
    }
}
